package common 
{
	import common.IState;
	/**
	 * ...
	 * @author Luke Van In
	 */
	public class StateController implements IStateController
	{
		
		private var _currentState:IState;
		
		
		
		/**
		 * Constructor
		 * 
		 * @param	currentState	The default(initial) state
		 */
		public function StateController() 
		{
			this._currentState = null;
		}
		
		
		
		
		/**
		 * Transitions to a state
		 *  
		 * @param	state
		 */
		public function gotoState(state:IState):void 
		{
			// don't transition to the state if the new state is the same as the current state
			if (state == this._currentState)
				return;
			
			// exit the current state (if any)
			if (this._currentState != null)
				this._currentState.exitState();
			
			// set the new state
			this._currentState = state;
			
			// enter the new state (if any)
			if (this._currentState != null)
				this._currentState.enterState();
		}
		
		
		
		
		/**
		 * 
		 * @param	state
		 */
		public function isCurrentState(state:IState):Boolean
		{
			return (state == this.getCurrentState());
		}
		
		
		
		/**
		 * 
		 * @return
		 */
		public function getCurrentState():IState
		{
			return this._currentState;
		}
		
		
	}

}